<template>
    <div class="uploadnote">
        <div class="head">
           <div class="back" @click="back">
            <img src="../assets/img/back.png" alt="">
           </div>
          <h1>发手记</h1>
          <p @click="send">
            发布
          </p>
        </div>
        <div class="addimg">
                  <van-uploader v-model="fileList"/>
        </div>
        <div class="addtitle">
            <input type="text" placeholder="填写标题可以获得更多推荐" v-model="title">
        </div>
        <div class="addcontent">
            <input type="text" placeholder="添加正文"   maxlength="300" v-model="content" >
        </div>


          
         
      
    </div>
</template>

<script>
import {Toast} from "vant"
    export default {
       data() {
        return {
          id:77,
          fileList: [],
          title:'',
          content:'',
         obj:{
              id:null,
              content:null,
              title:null,
              images:[],
              count:{
                   countlike:0,
                   countcomment:0,
                   countshare:0,
              },
              user:{
                  username:'小赵',
                  avatar:'https://img2.baidu.com/it/u=4043495183,2954281760&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
              },
              addtime: null,
              
           },
        }
       },
      methods: {
         send(){
            this.id+=1
            this.obj.id=this.id
            this.obj.content=this.content
            this.obj.title=this.title
            this.obj.addtime=new Date().getTime()
            console.log(this.obj.addtime);
            if (this.fileList.length>0) {
                 this.fileList.forEach(item => {
                     this.obj.images.push(item.content)
                 });
            }
            console.log(this.obj);
            
            window.localStorage.setItem('note',JSON.stringify(this.obj))
            Toast('发布成功')
            this.$router.push('/note')

       },
       back(){
        this.$router.go(-1)
       }
       
      },
      created() {
         let   temp = JSON.parse(window.localStorage.getItem('note'))
         console.log(temp);
        if (temp!=null) {
             this.id=temp.id
        }
        else{
            this.id=8888888888
        }
         console.log(this.id);
      },

    }
</script>

<style lang="less" scoped>
.uploadnote{
    min-height: 650px;
    background-color: #fff;
    .head{
        width: 90%;
        margin: 0 auto;
        display: flex;
        padding: 10px 0px;
        border-bottom: 1px solid #f2f2f2;
        justify-content: space-between;
        align-items: center;
        .back{
            img{
                width: 25px;
            }
        }
        h1{
           
            text-align: center;
        }
        p{
            padding: 5px 15px;
            background-color: red;
           border-radius: 15px;
           color: #fff;
           font-size: 12px;
        }
    }
    .addimg{
        padding: 10px 0px;
        width: 90%;
        margin: 0 auto;
          border-bottom: 1px solid #f2f2f2;
        
    }
    .addtitle,.addcontent{
        width: 90%;
        margin: 0 auto;
        padding: 10px 0px;
          border-bottom: 1px solid #f2f2f2;
        input{
            border: none;
            outline: none;
            width: 100%;
            font-size: 14px;
            height: 20px;
            
        }
    }
    .addcontent{
        height: 150px;
       input{
        white-space: wrap;
       }
    }
}

</style>